import type { questionSideState, questionSideListState } from '@/types/baseConfig'

const list: questionSideState[] = [
  {
    type: '容器',
    name: 'container',
    list: [
      {
        uid: '',
        label: '宫格',
        type: 'RowLayout',
        icon: 'esayIcon-gonggeshitu',
        commonForm: {
          labelKey: '',
          labelName: '',
          showLabel: true,
          show: true,
          editShow: true,
          disabled: false,
          showParams: []
        },
        RowLayoutForm: {
          xGap: 10,
          yGap: 10,
          autoFlow: '',
          alignItems: '',
          justifyItems: '',
          alignContent: '',
          justifyContent: '',
          childer: []
        },
        ColLayoutForm: {
          width: '1rf'
        }
      }
    ]
  },
  {
    type: '常用控件',
    name: 'assembly',
    list: [
      {
        uid: '',
        label: '文本输入',
        type: 'TextInput',
        icon: 'esayIcon-danhangshurukuang',
        commonForm: {
          labelKey: '',
          labelName: '',
          defaultValue: null,
          show: true,
          editShow: true,
          disabled: false,
          showLabel: true,
          showParams: []
        },
        formItem: {
          first: true,
          ignorePathChange: false,
          showFeedback: true,
          showLabel: true
        },
        ColLayoutForm: {
          width: '1rf'
        },
        TextInputForm: {
          autofocus: false,
          autosizeType: 'boolean',
          autosize: false,
          clearable: false,
          clearableIcon: '',
          countGraphemes: undefined,
          loading: undefined,
          maxlength: undefined,
          minlength: undefined,
          pair: false,
          passivelyActivated: false,
          placeholder: '请输入',
          readonly: false,
          round: false,
          rows: 3,
          separator: undefined,
          showCount: false,
          showPasswordOn: undefined,
          size: 'medium',
          status: undefined,
          type: 'text',
          passwordInvisibleIcon: '',
          passwordVisibleIcon: ''
        },
        ruleInfo: {
          isRules: true,
          isRequired: true,
          trigger: ['blur'],
          requiredTip: '请输入',
          regex: '',
          diyRule: []
        }
      },
      {
        uid: '',
        label: '数字输入',
        type: 'InputNumber',
        icon: 'esayIcon-jishuqi',
        commonForm: {
          labelKey: '',
          labelName: '',
          defaultValue: null,
          show: true,
          editShow: true,
          disabled: false,
          showLabel: true,
          showParams: []
        },
        formItem: {
          first: true,
          ignorePathChange: false,
          showFeedback: true,
          showLabel: true
        },
        ColLayoutForm: {
          width: '1rf'
        },
        InputNumberForm: {
          autofocus: false,
          bordered: true,
          buttonPlacement: 'right',
          clearable: false,
          disabled: false,
          format: undefined,
          keyboard: {
            ArrowUp: true,
            ArrowDown: true
          },
          loading: undefined,
          max: undefined,
          min: undefined,
          parse: undefined,
          placeholder: '请输入',
          precision: undefined,
          readonly: false,
          showButton: true,
          size: 'medium',
          status: undefined,
          step: 1,
          updateValueOnInput: true,
          addIcon: '',
          minusIcon: ''
        },
        ruleInfo: {
          isRules: true,
          isRequired: true,
          trigger: ['blur'],
          requiredTip: '请输入',
          regex: '',
          diyRule: []
        }
      },
      {
        uid: '',
        label: '选择器',
        type: 'SelectInput',
        icon: 'esayIcon-xuanzeqi',
        commonForm: {
          labelKey: '',
          labelName: '',
          defaultValue: null,
          show: true,
          editShow: true,
          disabled: false,
          showLabel: true,
          showParams: []
        },
        formItem: {
          first: true,
          ignorePathChange: false,
          showFeedback: true,
          showLabel: true
        },
        ColLayoutForm: {
          width: '1rf'
        },
        SelectInputForm: {
          loading: undefined,
          placeholder: '请选择',
          clearable: true,
          clearFilterAfterSelect: false,
          filterable: true,
          placement: 'bottom-start',
          options: [],
          fromType: 'common',
          fromTypeKey: '',
          query: 'query',
          getOptionsConfig: {
            api: '',
            method: 'get'
          },
          queryForm: []
        },
        ruleInfo: {
          isRules: true,
          isRequired: true,
          trigger: ['blur'],
          requiredTip: '请选择',
          regex: '',
          diyRule: []
        }
      }
    ]
  },
  {
    type: '封装组件',
    name: 'package',
    list: [
      {
        uid: '',
        label: '千位分隔符',
        type: 'InputNumber',
        icon: 'esayIcon-jishuqi',
        commonForm: {
          labelKey: '',
          labelName: '',
          defaultValue: null,
          show: true,
          editShow: true,
          disabled: false,
          showLabel: true,
          showParams: []
        },
        formItem: {
          first: true,
          ignorePathChange: false,
          showFeedback: true,
          showLabel: true
        },
        ColLayoutForm: {
          width: '1rf'
        },
        InputNumberForm: {
          autofocus: false,
          bordered: true,
          buttonPlacement: 'right',
          clearable: false,
          disabled: false,
          keyboard: {
            ArrowUp: true,
            ArrowDown: true
          },
          loading: undefined,
          max: undefined,
          min: undefined,
          format: `if (value === null) { backText = '' } else { backText = value.toLocaleString('en-US') }`,
          parse: `const nums = value.replace(/,/g, '').trim(); if (/^\\d+(\\.(\\d+)?)?$/.test(nums)) { backText = Number(nums) } else { backText = nums === '' ? null : Number.NaN }`,
          placeholder: '请输入',
          precision: undefined,
          readonly: false,
          showButton: true,
          size: 'medium',
          status: undefined,
          step: 1,
          updateValueOnInput: true,
          addIcon: '',
          minusIcon: ''
        },
        ruleInfo: {
          isRules: true,
          isRequired: true,
          trigger: ['blur'],
          requiredTip: '请输入',
          regex: '',
          diyRule: []
        }
      }
    ]
  }
]

export default list

interface itemState {
  type: string
  label: string
}
export function getTypeOptions(): itemState[] {
  const arr: itemState[] = []
  JSON.parse(JSON.stringify(list))
    .map((el: questionSideState) => {
      return el.list.map((item: questionSideListState) => {
        return {
          type: item.type,
          label: item.label
        }
      })
    })
    .flat()
    .filter((el: itemState) => {
      return !['Images', 'Annex', 'TreeSelect'].includes(el.type)
    })
    .filter((el: itemState) => {
      if (arr.every((item: itemState) => item.type !== el.type)) {
        arr.push(el)
      }
    })
  return arr
}

export function getBasicOptions(type: string) {
  return JSON.parse(JSON.stringify(list))
    .map((el: questionSideState) => {
      return el.list
    })
    .flat()
    .find((el: questionSideState) => {
      return el.type === type
    })
}

export function getAllName() {
  return JSON.parse(JSON.stringify(list)).map((el: questionSideState) => {
    return el.name
  })
}
